home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / benchmarks / copyin / RCS / copyin.c,v < prev   
Encoding:
Text File  |  1992-06-08  |  5.3 KB  |  248 lines

  1. head     1.3;
  2. branch   ;
  3. access   ;
  4. symbols  sprited:1.3.1;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.3
  10. date     92.06.07.18.10.48;  author kupfer;  state Exp;
  11. branches 1.3.1.1;
  12. next     1.2;
  13.  
  14. 1.2
  15. date     92.04.21.15.23.29;  author kupfer;  state Exp;
  16. branches ;
  17. next     1.1;
  18.  
  19. 1.1
  20. date     92.04.19.16.58.14;  author kupfer;  state Exp;
  21. branches 1.1.1.1;
  22. next     ;
  23.  
  24. 1.1.1.1
  25. date     92.06.07.18.13.23;  author kupfer;  state Exp;
  26. branches ;
  27. next     ;
  28.  
  29. 1.3.1.1
  30. date     92.06.07.18.14.10;  author kupfer;  state Exp;
  31. branches ;
  32. next     ;
  33.  
  34.  
  35. desc
  36. @Benchmark program that exercises copyin.
  37. @
  38.  
  39.  
  40. 1.3
  41. log
  42. @Add support for the other copy tests (copy out, Vm_MakeAccessible in
  43. and out).
  44. @
  45. text
  46. @/* Benchmark to test copyin/copyout performance. */
  47. /* $Header: /sprite/src/benchmarks/copyin/RCS/copyin.c,v 1.2 92/04/21 15:23:29 kupfer Exp Locker: kupfer $ */
  48.  
  49. #include <sprite.h>
  50. #include <option.h>
  51. #include <stdio.h>
  52. #include <spriteTime.h>
  53. #include <status.h>
  54. #include <sys/time.h>
  55. #include <unistd.h>
  56. #include <vmTypes.h>
  57.  
  58. #define BUFFER_SIZE    8192    /* see Vm_Cmd; XXX should go into VM header 
  59.                  * file */ 
  60.  
  61. char *buf;            /* Buffer to copy in from. */
  62.  
  63. int copySize[] = {0, 10, 100, 1024, 4096, 8192}; /* various amounts to copy */
  64. int numSizes = sizeof(copySize) / sizeof(int);
  65.  
  66. int iterations = 10000;        /* number of iterations for each copy size */
  67.  
  68. int spoilCOW = 0;        /* write to the buffer to prevent COW from 
  69.                  * giving optimistic results */
  70. int useMakeAccessible = 0;    /* use Vm_MakeAccessible & bcopy instead of 
  71.                  * copyin/out */ 
  72. int copyout = 0;        /* copy kernel->user instead of vice versa */
  73.  
  74. Option optionArray[] = {
  75.     {OPT_DOC, NULL, NULL,
  76.      "Exercise Sprite's copyin routine by passing various amounts\n\
  77. from a dummy buffer to the kernel and reporting the elapsed time."},
  78.     {OPT_TRUE, "cow", (Address)&spoilCOW,
  79.      "Prevent copy-on-write from improving the numbers"},
  80.     {OPT_INT, "iter", (Address)&iterations,
  81.      "Number of times to copy the buffer for each copy amount"},
  82.     {OPT_TRUE, "ma", (Address)&useMakeAccessible,
  83.      "Use Vm_MakeAccessible instead of Vm_CopyIn"},
  84.     {OPT_TRUE, "out", (Address)©out,
  85.      "Do copyout instead of copyin"},
  86. };
  87. int    numOptions = Opt_Number(optionArray);
  88.  
  89. void WriteToBuffer();
  90.  
  91. main(argc, argv)
  92.     int argc;
  93.     char *argv[];
  94. {
  95.     register int i;
  96.     Time startTime, endTime, totalTime;
  97.     int sizeIndex;
  98.     ReturnStatus status;
  99.     int command;        /* "copyin" versus "make accessible" */
  100.     char *operation;        /* printable name of operation */
  101.  
  102.     (void)Opt_Parse(argc, argv, optionArray, numOptions, 0);
  103.     buf = valloc(BUFFER_SIZE);
  104.     if (buf == NULL) {
  105.     fprintf(stderr, "copyin: no memory.\n");
  106.     exit(1);
  107.     }
  108.     if (useMakeAccessible) {
  109.     if (copyout) {
  110.         operation = "MakeAccessible (out)";
  111.         command = VM_DO_MAKE_ACCESS_OUT;
  112.     } else {
  113.         operation = "MakeAccessible (in)";
  114.         command = VM_DO_MAKE_ACCESS_IN;
  115.     }
  116.     } else {
  117.     if (copyout) {
  118.         operation = "Vm_CopyOut";
  119.         command = VM_DO_COPY_OUT;
  120.     } else {
  121.         operation = "Vm_CopyIn";
  122.         command = VM_DO_COPY_IN;
  123.     }
  124.     }
  125.  
  126.     for (sizeIndex = 0; sizeIndex < numSizes; ++sizeIndex) {
  127.     status = Vm_Cmd(VM_SET_COPY_SIZE, copySize[sizeIndex]);
  128.     if (status != SUCCESS) {
  129.         fprintf(stderr, "Can't set copy size to %d: %s\n",
  130.             copySize[sizeIndex], Stat_GetMsg(status));
  131.         exit(1);
  132.     }
  133.     totalTime = time_ZeroSeconds;
  134.     gettimeofday((struct timeval *)&startTime,0);    
  135.     for (i = 0; i < iterations; i++) {
  136.         status = Vm_Cmd(command, buf);
  137.         if (status != SUCCESS) {
  138.         fprintf(stderr, "Can't copy %d bytes: %s\n",
  139.             copySize[sizeIndex], Stat_GetMsg(status));
  140.         exit(1);
  141.         }
  142.         if (spoilCOW) {
  143.         WriteToBuffer(BUFFER_SIZE, buf);
  144.         }
  145.     }
  146.     gettimeofday((struct timeval *)&endTime,0);
  147.     Time_Subtract(endTime, startTime, &totalTime);
  148.     printf("Using %s: copy %4d bytes %d times: %2d.%03d sec\n",
  149.            operation, copySize[sizeIndex], iterations,
  150.            totalTime.seconds, totalTime.microseconds/1000);
  151.     }
  152. }
  153.  
  154. void
  155. WriteToBuffer(length, buffer)
  156.     int length;            /* bytes in buffer */
  157.     char *buffer;        /* buffer to write to */
  158. {
  159.     char *cPtr;
  160.  
  161.     for (cPtr = buffer; cPtr < buffer + length; cPtr += 1024) {
  162.     *cPtr = 'a';
  163.     }
  164. }
  165. @
  166.  
  167.  
  168. 1.3.1.1
  169. log
  170. @Branch for Sprite server.
  171. @
  172. text
  173. @d2 1
  174. a2 1
  175. /* $Header: /sprite/src/benchmarks/copyin/RCS/copyin.c,v 1.3 92/06/07 18:10:48 kupfer Exp $ */
  176. @
  177.  
  178.  
  179. 1.2
  180. log
  181. @Valloc the buffer.
  182. @
  183. text
  184. @d2 1
  185. a2 1
  186. /* $Header: /sprite/src/benchmarks/copyin/RCS/copyin.c,v 1.1 92/04/19 16:58:14 kupfer Exp Locker: kupfer $ */
  187. d25 3
  188. d37 4
  189. d54 2
  190. d63 17
  191. d91 1
  192. a91 1
  193.         status = Vm_Cmd(VM_DO_COPY_IN, buf);
  194. d93 1
  195. a93 1
  196.         fprintf(stderr, "Can't do copyin of %d bytes: %s\n",
  197. d103 2
  198. a104 2
  199.     printf("copy %4d bytes %d times: %2d.%03d sec\n",
  200.            copySize[sizeIndex], iterations,
  201. @
  202.  
  203.  
  204. 1.1
  205. log
  206. @Initial revision
  207. @
  208. text
  209. @d2 1
  210. a2 1
  211. /* $Header: /sprite/src/benchmarks/template/RCS/t.c,v 1.2 92/04/10 15:31:37 kupfer Exp $ */
  212. d10 1
  213. d16 1
  214. a16 1
  215. char buf[BUFFER_SIZE];        /* Buffer to copy in from. */
  216. d49 5
  217. @
  218.  
  219.  
  220. 1.1.1.1
  221. log
  222. @Initial version for sprited.
  223. @
  224. text
  225. @d2 1
  226. a2 1
  227. /* $Header: /user5/kupfer/spriteserver/src/benchmarks/copyin/RCS/copyin.c,v 1.2 92/04/24 00:03:56 kupfer Exp $ */
  228. a9 1
  229. #include <unistd.h>
  230. d12 2
  231. a13 1
  232. char *buf;
  233. d15 2
  234. a47 5
  235.     buf = valloc(VM_DO_COPY_MAX_SIZE);
  236.     if (buf == NULL) {
  237.     fprintf(stderr, "copyin: no memory.\n");
  238.     exit(1);
  239.     }
  240. d50 6
  241. d59 1
  242. a59 1
  243.         status = Vm_Cmd(VM_DO_COPY_IN, copySize[sizeIndex], buf);
  244. d66 1
  245. a66 1
  246.         WriteToBuffer(VM_DO_COPY_MAX_SIZE, buf);
  247. @
  248.